package com.mysterymall.Controller.Admin;

import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Service.GoodsCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName com.mysterymall.Controller.Admin
 * @Description
 * @Author HuangWX
 * @Time 2023/11/29  13:27
 */
@RestController
@RequestMapping("/goodsCategory")
public class AdminGoodsCategoryCont {

    private final GoodsCategoryService goodsCategoryService;

    /**
     * 构造器注入
     * @param goodsCategoryService 商品类别服务
     */
    public AdminGoodsCategoryCont(GoodsCategoryService goodsCategoryService) {
        this.goodsCategoryService = goodsCategoryService;
    }

    /**
     * 添加商品类别
     * @param name 商品类别名称
     * @return Result
     */
    @GetMapping("/addCategory")
    @Log
    public Result addCategory(@RequestParam("name")String name){
        return goodsCategoryService.addGoodsCategory(name);
    }

    /**
     * 获取商品类别
     * @return Result
     */
    @GetMapping("/getCategory")
    @Log
    public Result getCategory(){
        return goodsCategoryService.getGoodsCategory();
    }

    /**
     * 修改商品类别
     * @param id 商品类别ID
     * @return Result
     */
    @GetMapping("/deleteCategory")
    @Log
    public Result deleteCategory(@RequestParam("id")String id){
        return goodsCategoryService.deleteGoodsCategory(id);
    }


    /**
     * 获取展示的商品类别
     * @param request 请求
     * @return Result
     */
    @GetMapping("/getShowCategory")
    @Log
    public Result getShowCategory(HttpServletRequest request){
        return goodsCategoryService.getShowGoodsCategory(request);
    }
}
